package com.lancoo.znbkxx.teacher.ui.activity


import android.annotation.SuppressLint
import android.webkit.WebChromeClient
import android.webkit.WebSettings
import android.webkit.WebView
import android.webkit.WebViewClient
import com.lancoo.cpbase.authentication.base.CurrentUser
import com.lancoo.znbkxx.teacher.Ext.Companion.COURSE_CLASSID
import com.lancoo.znbkxx.teacher.Ext.Companion.GLOBAL_GRADE
import com.lancoo.znbkxx.teacher.Ext.Companion.PLATFORM_URL
import com.lancoo.znbkxx.teacher.R
import com.lancoo.znbkxx.teacher.base.BaseVMActivity
import com.lancoo.znbkxx.teacher.databinding.ActivityAnalysisBinding
import com.lancoo.znbkxx.teacher.viewmodel.PaperViewModel


/**
 * @author : Admin
 * @date   : 2019/11/12 10:43
 * @desc   :
 */
class AssessActivity : BaseVMActivity<PaperViewModel, ActivityAnalysisBinding>() {
    override fun setLayoutID(): Int {
        return R.layout.activity_analysis
    }

    @SuppressLint("SetJavaScriptEnabled")
    override fun initView() {
        binding.tvTitle.text = getString(R.string.assess)
        binding.sbtnBack.setOnClickListener { finish() }
        binding.wv.apply {
            WebView.setWebContentsDebuggingEnabled(true)
            settings.javaScriptEnabled = true
            settings.useWideViewPort = true
            settings.layoutAlgorithm = WebSettings.LayoutAlgorithm.NARROW_COLUMNS
            settings.loadWithOverviewMode = true
            webChromeClient = WebChromeClient()
            webViewClient = WebViewClient()
            loadUrl("${PLATFORM_URL}Web/PaperAssess/analysis-m.html?SchoolID=${CurrentUser.getSchoolID()}&GlobalGrade=$GLOBAL_GRADE&CourseClassID=$COURSE_CLASSID&Layer=2&TeacherID=${CurrentUser.UserID}&token=${CurrentUser.Token}")
        }
    }

    override fun providerVMClass(): Class<PaperViewModel>? {
        return PaperViewModel::class.java
    }

//    override fun initData() {
//        viewModel.getDataAnalyze(
//            COURSE_CLASSID,
//            KEY,
//            CurrentUser.SchoolID,
//            CurrentUser.Token,
//            CurrentUser.UserID
//        )
//    }

//    @SuppressLint("SetTextI18n")
//    override fun startObserve() {
//        viewModel.mAnalysisInfo.observe(this, Observer {
//            binding.tvStr.text = "已有试卷效度评估-${it.CoursrClassName}"
//            var totalCount = 0
//            it.LayerList.forEach {
//                totalCount += it.Count.toInt()
//            }
//            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
//                binding.tvLayer.text = Html.fromHtml(
//                    getString(
//                        R.string.layer,
//                        it.CoursrClassName,
//                        totalCount,
//                        it.LayerList[0].Count.toInt(),
//                        it.LayerList[1].Count.toInt(),
//                        it.LayerList[2].Count.toInt(),
//                        it.ReleasedCount
//                    ), Html.FROM_HTML_MODE_COMPACT
//                )
//            } else {
//                binding.tvLayer.text = Html.fromHtml(
//                    getString(
//                        R.string.layer,
//                        it.CoursrClassName,
//                        totalCount,
//                        it.LayerList[0].Count.toInt(),
//                        it.LayerList[1].Count.toInt(),
//                        it.LayerList[2].Count.toInt(),
//                        it.ReleasedCount
//                    )
//                )
//            }
//            if (it.DataAnalyze.Effective > 0) {
//                binding.pbEffective.setPercentData(
//                    (it.DataAnalyze.Effective).toFloat(), "%", DecelerateInterpolator()
//                )
//                binding.tvEffective.text = "${BigDecimal(it.DataAnalyze.Effective).setScale(
//                    2,
//                    BigDecimal.ROUND_HALF_UP
//                )}%"
//            } else {
//                binding.pbEffective.setPercentData(
//                    0f, "%", DecelerateInterpolator()
//                )
//                binding.tvEffective.text = "0%"
//            }
//            if (it.DataAnalyze.TotalImpCount + it.DataAnalyze.TotalMainCount + it.DataAnalyze.TotalMinorCount > 0) {
//                val percentCoverage =
//                    BigDecimal((it.DataAnalyze.CoverImpCount + it.DataAnalyze.CoverMainCount + it.DataAnalyze.CoverMinorCount).toDouble() / (it.DataAnalyze.TotalImpCount + it.DataAnalyze.TotalMainCount + it.DataAnalyze.TotalMinorCount) * 100).setScale(
//                        2,
//                        RoundingMode.DOWN
//                    )
//                binding.pbCoverage.setPercentData(
//                    percentCoverage.toFloat(),
//                    "%",
//                    DecelerateInterpolator()
//                )
//                binding.tvCoverage.text = "$percentCoverage%"
//            } else {
//                binding.pbCoverage.setPercentData(0f, "%", DecelerateInterpolator())
//                binding.tvCoverage.text = "0%"
//            }
//            if (it.DataAnalyze.MatchRate > 0) {
//                binding.pbMatch.setPercentData(
//                    (it.DataAnalyze.MatchRate).toFloat(), "%", DecelerateInterpolator()
//                )
//                binding.tvMatch.text = "${BigDecimal(it.DataAnalyze.MatchRate).setScale(
//                    2,
//                    BigDecimal.ROUND_HALF_UP
//                )}%"
//            } else {
//                binding.pbMatch.setPercentData(0f, "%", DecelerateInterpolator())
//                binding.tvMatch.text = "0%"
//            }
//            /*
//        * 处理难度系数进度
//        * */
//            val mIvThumbNanDu = binding.include5.findViewById<ImageView>(R.id.iv_thumbNadu)
//            val mTvNanDu = binding.include5.findViewById<TextView>(R.id.tv_nandu)
//            val mIvSeekBarNanDu = binding.include5.findViewById<ImageView>(R.id.iv_seekbarNandu)
//            val dNandu = it.DataAnalyze.Difficulty
//            mIvSeekBarNanDu.post {
//                val width = mIvSeekBarNanDu.width
//                val widthTv = mTvNanDu.width
//                var left_thumbNandu = (width * dNandu).toInt() - 10//10为修正值
//                if (dNandu == 0.0) {
//                    left_thumbNandu = 0
//                }
//                mIvThumbNanDu.setPadding(left_thumbNandu, 0, 0, 0)
//                var leftTvNandu = (width * dNandu).toInt() - widthTv / 2 - 10
//                val maxLeftTvNandu = width - widthTv - 10
//                if (leftTvNandu > maxLeftTvNandu) {
//                    leftTvNandu = maxLeftTvNandu + 4
//                }
//                val minLeftTvNandu = widthTv / 2
//                if (left_thumbNandu < minLeftTvNandu) {
//                    if (left_thumbNandu == 0) {
//                        leftTvNandu = 2
//                    } else {
//                        leftTvNandu = minLeftTvNandu - (width * dNandu).toInt() + 2//2为修正值
//                    }
//                }
//                mTvNanDu.setPadding(leftTvNandu, 0, 0, 0)
//
//                if (dNandu < 0.2 || dNandu > 0.8) {
//                    mIvThumbNanDu.setImageResource(R.mipmap.icon_thumb_yellow)
//                    mTvNanDu.setTextColor(resources.getColor(R.color.lancoooOrange))
//                    val df = DecimalFormat("######0.00")
//                    mTvNanDu.text = df.format(floor(dNandu * 100) / 100) + "(较易)"
//                } else if (dNandu >= 0.2 && dNandu < 0.4) {
//                    mIvThumbNanDu.setImageResource(R.mipmap.icon_thumb_red)
//                    mTvNanDu.setTextColor(resources.getColor(R.color.lancoooRed))
//                    val df = DecimalFormat("######0.00")
//                    mTvNanDu.text = df.format(floor(dNandu * 100) / 100) + "(较难)"
//                } else if (dNandu in 0.4..0.6) {
//                    mIvThumbNanDu.setImageResource(R.mipmap.icon_thumb_green)
//                    mTvNanDu.setTextColor(resources.getColor(R.color.lancoooGreen))
//                    val df = DecimalFormat("######0.00")
//                    mTvNanDu.text = df.format(floor(dNandu * 100) / 100) + "(适中)"
//                }
//            }
//
//
//            /*
//         * 处理区分度系数进度
//         * */
//            val mIvThumbQufendu = binding.include6.findViewById<ImageView>(R.id.iv_thumbQufendu)
//            val mTvQufendu = binding.include6.findViewById<TextView>(R.id.tv_qufendu)
//            val mIvSeekBarQufendu = binding.include6.findViewById<ImageView>(R.id.iv_seekbarQufendu)
//            val dQufendu = it.DataAnalyze.Distinguish
//            mIvSeekBarQufendu.post {
//                val width = mIvSeekBarQufendu.width
//                val widthTv = mTvQufendu.width
//                var left_thumbQufendu = (width * dQufendu).toInt() - 10//10为修正值
//                if (dQufendu == 0.0) {
//                    left_thumbQufendu = 0
//                }
//                mIvThumbQufendu.setPadding(left_thumbQufendu, 0, 0, 0)
//                var leftTvQufendu = (width * dQufendu).toInt() - widthTv / 2 - 10
//                val maxLeftTvQufendu = width - widthTv - 10
//                if (leftTvQufendu > maxLeftTvQufendu) {
//                    leftTvQufendu = maxLeftTvQufendu + 4
//                }
//                val minLeftTvQufendu = widthTv / 2
//                if (left_thumbQufendu < minLeftTvQufendu) {
//                    if (left_thumbQufendu == 0) {
//                        leftTvQufendu = 2
//                    } else {
//                        leftTvQufendu = minLeftTvQufendu - (width * dQufendu).toInt() + 2//2为修正值
//                    }
//                }
//                mTvQufendu.setPadding(leftTvQufendu, 0, 0, 0)
//
//                if (dQufendu <= 0.2) {
//                    mIvThumbQufendu.setImageResource(R.mipmap.icon_thumb_red)
//                    mTvQufendu.setTextColor(resources.getColor(R.color.lancoooRed))
//                    val df = DecimalFormat("######0.00")
//                    mTvQufendu.text = df.format(floor(dQufendu * 100) / 100) + "(差)"
//                } else if (dQufendu > 0.2 && dQufendu <= 0.3) {
//                    mIvThumbQufendu.setImageResource(R.mipmap.icon_thumb_yellow)
//                    mTvQufendu.setTextColor(resources.getColor(R.color.lancoooOrange))
//                    val df = DecimalFormat("######0.00")
//                    mTvQufendu.text = df.format(floor(dQufendu * 100) / 100) + "(较好)"
//                } else {
//                    mIvThumbQufendu.setImageResource(R.mipmap.icon_thumb_green)
//                    mTvQufendu.setTextColor(resources.getColor(R.color.lancoooGreen))
//                    val df = DecimalFormat("######0.00")
//                    mTvQufendu.text = df.format(floor(dQufendu * 100) / 100) + "(很好)"
//                }
//            }
//
//            /*
//         * 处理曝光度系数进度
//         * */
//            val mIvThumbBaoguangdu =
//                binding.include7.findViewById<ImageView>(R.id.iv_thumbBaoguangdu)
//            val mTvBaoguangdu = binding.include7.findViewById<TextView>(R.id.tv_baoguangdu)
//            val mIvSeekBarBaoguangdu =
//                binding.include7.findViewById<ImageView>(R.id.iv_seekbarBaoguangdu)
//            val dBaoguangdu = it.DataAnalyze.ExposureRate
//            mIvSeekBarBaoguangdu.post {
//                val width = mIvSeekBarBaoguangdu.width
//                val widthTv = mTvBaoguangdu.width
//                var left_thumbBaoguangdu = (width * dBaoguangdu).toInt() - 10//10为修正值
//                if (dBaoguangdu == 0.0) {
//                    left_thumbBaoguangdu = 0
//                }
//                mIvThumbBaoguangdu.setPadding(left_thumbBaoguangdu, 0, 0, 0)
//                var leftTvBaoguangdu = (width * dBaoguangdu).toInt() - widthTv / 2 - 10
//                val maxLeftTvBaoguangdu = width - widthTv - 10
//                if (leftTvBaoguangdu > maxLeftTvBaoguangdu) {
//                    leftTvBaoguangdu = maxLeftTvBaoguangdu + 4
//                }
//                val minLeftTvBaoguangdu = widthTv / 2
//                if (left_thumbBaoguangdu < minLeftTvBaoguangdu) {
//                    if (left_thumbBaoguangdu == 0) {
//                        leftTvBaoguangdu = 2
//                    } else {
//                        leftTvBaoguangdu =
//                            minLeftTvBaoguangdu - (width * dBaoguangdu).toInt() + 2//2为修正值
//                    }
//                }
//                mTvBaoguangdu.setPadding(leftTvBaoguangdu, 0, 0, 0)
//
//                if (dBaoguangdu > 0.01) {
//                    mIvThumbBaoguangdu.setImageResource(R.mipmap.icon_thumb_red)
//                    mTvBaoguangdu.setTextColor(resources.getColor(R.color.lancoooRed))
//                    val df = DecimalFormat("######0.00")
//                    mTvBaoguangdu.text = df.format(floor(dBaoguangdu * 100) / 100) + "(差)"
//                } else {
//                    mIvThumbBaoguangdu.setImageResource(R.mipmap.icon_thumb_green)
//                    mTvBaoguangdu.setTextColor(resources.getColor(R.color.lancoooGreen))
//                    val df = DecimalFormat("######0.00")
//                    mTvBaoguangdu.text = df.format(floor(dBaoguangdu * 100) / 100) + "(良好)"
//                }
//            }
//        })
//    }
}